package com.njitt.bysj.controller;

import com.njitt.bysj.base.BaseController;
import com.njitt.bysj.base.ResultInfo;
import com.njitt.bysj.bean.BasicQuotationBean;
import com.njitt.bysj.bean.ProjectBean;
//import com.njitt.bysj.bean.ProjectEmpBean;
import com.njitt.bysj.bean.PurchaseRequestBean;
import com.njitt.bysj.model.PickStockModel;
import com.njitt.bysj.query.BasicSaleQuery;
import com.njitt.bysj.query.ProjectQuery;
import com.njitt.bysj.srevice.SaleService;
import com.njitt.bysj.utils.AssertUtil;
import com.sun.org.apache.regexp.internal.RE;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.swing.plaf.synth.SynthColorChooserUI;
import java.io.File;
import java.io.IOException;
import java.sql.ResultSet;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

/**
 * @description: 销售控制器
 * @author: wyj
 * @time: 2022/3/20 21:28
 */
@Controller
@RequestMapping("sale")
public class SaleController extends BaseController {
    @Resource
    private SaleService saleService;


    @RequestMapping("toSalePage")
    public String toSalePage() {
        return "sale/sale";
    }

    @RequestMapping("basic_list")
    @ResponseBody
    public Map<String, Object> basicList(BasicSaleQuery query) {
        return saleService.basic_list(query);
    }


    @RequestMapping("toAddBasicPage")
    public String toAddBasicPage() {
        return "sale/addBasic";
    }

    @RequestMapping("addBasic")
    @ResponseBody
    public ResultInfo addBasic(BasicQuotationBean basicQuotationBean) {
        saleService.addBasic(basicQuotationBean);
        return success();
    }

    @RequestMapping("toUpdateBasicPage")
    public String toUpdateBasicPage(Integer id, Model model) {
        BasicQuotationBean basicQuotationBean = saleService.queryBasicByPrimaryKey(id);
        model.addAttribute("basic", basicQuotationBean);
        return "sale/updateBasic";
    }

    @RequestMapping("updateBasic")
    @ResponseBody
    public ResultInfo updateBasic(BasicQuotationBean basicQuotationBean) {
        saleService.updateBasic(basicQuotationBean);
        return success("success");
    }

    @RequestMapping("toProjectPage")
    public String toProjectPage() {
        return "sale/project";
    }

    @RequestMapping("projectList")
    @ResponseBody
    public Map<String, Object> projectList(ProjectQuery projectQuery) {
        return saleService.projectList(projectQuery);
    }


    @RequestMapping("toApprovePage")
    public String toApprovePage(Integer basicId, HttpServletRequest request) {
        BasicQuotationBean basicQuotationBean = saleService.selectByBasicId(basicId);
        request.setAttribute("basic", basicQuotationBean);
        return "sale/approve";
    }

    @RequestMapping("addProject")
    @ResponseBody
    public ResultInfo addProject(ProjectBean projectBean) {
        /**
         * @description:审批添加项目列表
         * @return:  * @param projectBean
         * @author:
         * @time: 2022/4/15 15:13
         */
        saleService.addProject(projectBean);
        return success("success");
    }

    @RequestMapping("toPickStock")
    public String toPickStock() {
        return "sale/toPickStock";
    }

    @RequestMapping("addPickStock")
    @ResponseBody
    public ResultInfo addPickStock(PickStockModel pickStockModel) {
        saleService.addPickStock(pickStockModel);
        return success("success");
    }
}

